<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html><html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>物料管理</title>
    <style>
        .newtitle {
            PADDING-LEFT: 15px;
            BACKGROUND: url('');
            PADDING-BOTTOM: 4px;
            BORDER-LEFT: #c0dcf2 1px solid;
        }
    </style>
    <jsp:include page="easyuiIncludeJS.jsp"/>
    <script type="text/javascript">
        $(function () {
            var pager = $(".easyui-datagrid").datagrid('getPager');
            $(pager).pagination({
                total:${pager.totalRows},
                pageSize:${pager.pageRow},
                displayMsg: '{from}-{to}/{total}',
                pageNumber:${pager.cur_page},
                afterPageText: '页，共{pages}页',
                pageList: [5, 10, 20, 30, 50, 100],
                loading: false,
                showPageList: true,
                showRefresh: true,
                //刷新方法
                onBeforeRefresh: function (p, s) {
                    location.href = "${pageContext.request.contextPath }/admin/material/materiallist?cur_page=" + p + "&pageRow=" + s;
                },
                onSelectPage: function (p, s) {
                    location.href = "${pageContext.request.contextPath }/admin/material/materiallist?cur_page=" + p + "&pageRow=" + s;
                }
            });
        });
        function delcalss(materialId){
        	if(!confirm('删除确定')){
        		return;
        	}
           var url = "${pageContext.request.contextPath}/admin/material/materialdel";
            var materialId = materialId;
            $.post(
                url,
                {
                    "materialId":materialId
                },
                function (data) {
                    location.href = "${pageContext.request.contextPath }/admin/material/materiallist";
                },
                "json"
            );
        }
        function save() {
            if ($("#materialCode").val()==""){
                alert("请输入物料编码");
                $("#materialCode").focus();
                return;
            }
            if ($("#materialName").val()==""){
                alert("请输入物料名称");
                $("#materialName").focus();
                return;
            }
            var url="${pageContext.request.contextPath}/admin/material/init"
            var materialId=$("#materialId").val();
            var materialName=$("#materialName").val();
            var prodTypeId=$("#prodTypeId").val();
            var materialCode=$("#materialCode").val();
            var style = $("#style").val();
            var remark = $("#remark").val();
            var materialUnit = $("#materialUnit").val();
            var bagUnit = $("#bagUnit").val();
            var materialTypeId = $("#materialTypeId").val();
            var formula = $("#formula").val();
            $.post(
                url,
                {
                    "materialId":materialId,
                    "materialName":materialName,
                    "prodTypeId":prodTypeId,
                    "materialCode":materialCode,
                    "style":style,
                    "remark":remark,
                    "materialUnit":materialUnit,
                    "bagUnit":bagUnit,
                    "materialTypeId":materialTypeId,
                    "formula":formula
                },
                function(data){
                    window.location.href = "${pageContext.request.contextPath}/admin/material/materiallist";
                },
                "json"
            );
        }

        function test(value, res) {
            var materialId = res.materialId;
            var url="${pageContext.request.contextPath}/admin/material/json";
            $.post(
                url,
                {
                    "materialId":materialId
                },
                updemp,
                "json"
            );
        }
        function updemp(date) {
            $("#materialId").val(date.materialList.materialId);
            $("#materialName").val(date.materialList.materialName);
            $("#materialCode").val(date.materialList.materialCode);
            $("#prodTypeId").val(date.materialList.prodTypeId);
            $("#materialTypeId").val(date.materialList.materialTypeId);
            $("#style").val(date.materialList.style);
            $("#remark").val(date.materialList.remark);
            $("#materialUnit").val(date.materialList.materialUnit);
            $("#formula").val(date.materialList.formula);
            $("#bagUnit").val(date.materialList.bagUnit);
            
        }
        function closeSubmit() {
            $("#materialId").val("");
            $("#materialName").val("");
            $("#materialCode").val("");
            $("#style").val("");
            $("#remark").val("");
            $("#materialUnit").val("");
            $("#bagUnit").val("");
            $("#formula").val("");
        }

    </script>
</head>
<body>

<table  class="easyui-datagrid" pagination="true" fitColumns="auto"  style="height:350px" singleSelect="true" data-options="onClickRow:test">
    <thead>
    <tr>
        <th align="center" width="60" field="materialId">序号</th>
        <th align="center" width="80" field="materialCode">物料编码</th>
        <th align="center" width="100" field="materialName">物料名称</th>
        <th align="center" width="80" field="materialTypeCode">物料类别编码</th>
        <th align="center" width="100" field="materialTypeName">物料类别名称</th>
        <th align="center" width="80" field="prodTypeCode">品种类别编码</th>
        <th align="center" width="100" field="prodTypeName">品种类别名称</th>
        <th align="center" width="100" field="style">规格</th>
        <th align="center" width="80" field="materialUnit">净重计量单位</th>
        <th align="center" width="80" field="bagUnit">包装计量单位</th>
        <th align="center" width="150" field="formula">批号规则</th>
        <th align="center" width="100" field="remark">物料描述</th>
        <th align="center" field="opt">操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${materialList}" var="d">
        <tr>
            <td>${d.materialId}</td>
            <td>${d.materialCode}</td>
            <td>${d.materialName}</td>
            <td>${d.materialTypeCode}</td>
            <td>${d.materialTypeName}</td>
            <td>${d.prodTypeCode}</td>
            <td>${d.prodTypeName}</td>
            <td>${d.style}</td>
            <td>${d.materialUnit}</td>
            <td>${d.bagUnit}</td>
            <td>${d.formula}</td>
            <td>${d.remark}</td>
            <td>
                <a href="javascript:void(0);" class="easyui-linkbutton" plain="true" icon="icon-remove"  onclick='delcalss(${d.materialId});'> 删除</a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div id="tt" class="easyui-tabs" style="height:200px">
    <div title="物料管理" data-options="closable:false,cache:false" style="padding:0px;">
	    <div class="newtitle">
	        <th>
				<a class="easyui-linkbutton " href="javascript:void(0);" plain="true" icon="icon-add" onclick="closeSubmit();">新增</a>
	            <a class="easyui-linkbutton " href="javascript:void(0);" plain="true" icon="icon-save" onclick="save();">保存</a>
	        </th>
	    </div>
        <form id="td" name="td" method="post" style="margin-left: 50px;">
            <hidden id="materialId" name="materialId"></hidden>
            <table border="0" width="100%">
            	<tr height="40">
	                <td align="right"><label class="label-top">物料编码:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="materialCode" name="materialCode" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">物料名称:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="materialName" name="materialName" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">产品规格:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="style" name="style" style="width: 220px;"></td>
                </tr>
            	<tr height="40">
	                <td align="right"><label class="label-top">净重计量单位:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="materialUnit" name="materialUnit" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">所属品种:</label></td>
	                <td>
		                <select editable="false" id="prodTypeId" name="prodTypeId" style="width:220px;">
		                    <c:forEach items="${pList}" var="d">
		                        <c:if test="${d.prodTypeId!=material.prodTypeId}">
		                            <option value="${d.prodTypeId}">${d.prodTypeName}(${d.prodTypeCode})</option>
		                        </c:if>
		                        <c:if test="${d.prodTypeId==material.prodTypeId}">
		                            <option value="${d.prodTypeId}" selected="selected">${d.prodTypeName}(${d.prodTypeCode})</option>
		                        </c:if>
		                    </c:forEach>
		                </select>
	                </td>
	                <td align="right"><label class="label-top">所属物料类别:</label></td>
	                <td>
		                <select editable="false" id="materialTypeId" name="materialTypeId" style="width:220px;">
		                    <c:forEach items="${materialTypeList}" var="d">
		                        <c:if test="${d.materialTypeId!=material.materialTypeId}">
		                            <option value="${d.materialTypeId}">${d.materialTypeName}(${d.materialTypeCode})</option>
		                        </c:if>
		                        <c:if test="${d.materialTypeId==material.materialTypeId}">
		                            <option value="${d.materialTypeId}" selected="selected">${d.materialTypeName}(${d.materialTypeCode})</option>
		                        </c:if>
		                    </c:forEach>
		                </select>
	                </td>
                </tr>
            	<tr height="40">
	                <td align="right"><label class="label-top">包装计量单位:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="bagUnit" name="bagUnit" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">批号规则:</label></td>
	                <td ><input class="easyui-textbox" data-options="required:true" id="formula" name="formula" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">物料描述:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="remark" name="remark" style="width: 220px;"></td>
                </tr>
            </table>
        </form>
    </div>
</div>
</body>
</html>
